package com.trkj.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.jpa.CcHospFloorDAO;
import com.trkj.dao.jpa.CcStoreyDAO;
import com.trkj.pojos.CcStorey;
import com.trkj.vo.CcStoreyVo;

@Service
@Transactional
public class CcStoreyService {

	@Autowired
	private CcStoreyDAO csDAO;
	@Autowired
	private CcHospFloorDAO chDAO;
	
	public Map<String, Object> queryAllStorey(){
		//获取总的记录条数
		long total = csDAO.count();
		List<CcStorey> list=(List<CcStorey>) csDAO.findAll();
		Map<String, Object> map = new HashMap<>();
		map.put("total", total);
		map.put("rows", poStoreyList2VoList(list));
		return map;
	} 
	
	public List<CcStoreyVo> poStoreyList2VoList(List<CcStorey> list){
			if(list == null) return null;
			List<CcStoreyVo> listVo = new ArrayList<>();
			for(CcStorey cs: list){
				CcStoreyVo csVo = new CcStoreyVo();
				csVo.setStoreyId(cs.getStoreyId());
				csVo.setStoName(cs.getStoName());
				csVo.setFloor_id(cs.getSfloorId().longValue());
				csVo.setFloor_name(chDAO.queryName(csVo.getFloor_id()));
				csVo.setAddress(csVo.getFloor_name()+csVo.getStoName());
				listVo.add(csVo);
			}
			return listVo;
		
	}
	
}
